# -*-coding:utf-8 -*-
from django.shortcuts import render
from schedule.api.serializers import *
from schedule.models import *
from rest_framework import generics, viewsets
from rest_framework.decorators import list_route, detail_route

from core.api.views import HtmlModelViewSet, DynamicFieldsViewMixin


class WatchDutyAPIView(DynamicFieldsViewMixin, viewsets.ModelViewSet):
    """
    值班排班
    """
    queryset = WatchDuty.objects.all()
    serializer_class = WatchDutySerializer
    # permission_classes = (IsAdminUser,)
    ordering_fields = ('date_start', 'who')
    search_fields = ('who__name',)
    filter_fields = ('type', 'department')

    @list_route()
    def today(self, request, *args, **kwargs):
        self.queryset = WatchDuty.objects.today()
        print (">>>>>>>>>", self.queryset)
        return self.list(request, *args, **kwargs)

    @list_route()
    def week(self, request, *args, **kwargs):
        self.queryset = WatchDuty.objects.current_week()

        return self.list(request, *args, **kwargs)

    @list_route()
    def month(self, request, *args, **kwargs):
        self.queryset = WatchDuty.objects.current_month()
        return self.list(request, *args, **kwargs)


class WhereToAPIView(DynamicFieldsViewMixin, viewsets.ModelViewSet):
    """
    去向公示
    """
    queryset = WhereTo.objects.all()
    serializer_class = WhereToSerializer
    # permission_classes = (IsAdminUser,)
    ordering_fields = ('leave_time',)
    search_fields = ('who__name',)
    filter_fields = ('department',)
